package com.paomi.client.activity.load;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.hannesdorfmann.mosby3.mvp.MvpView;
import com.paomi.client.R;
import com.paomi.client.activity.load.presenter.LoadingPresenter;
import com.paomi.client.activity.login.LoginActivity;
import com.paomi.client.activity.main.MainActivity;
import com.paomi.client.base.BaseMvpActivity;
import com.paomi.client.utils.SPUtil;

import butterknife.BindView;

/**
 * Created by pc on 2018/10/24
 * Describe:
 * com.paomi.client.activity.load
 */
public class LoadingActivity extends BaseMvpActivity<MvpView, LoadingPresenter> {

    @BindView(R.id.splash_iv)
    ImageView splashIv;

    @NonNull
    @Override
    protected int getLayoutId() {
        return R.layout.activity_loading;
    }

    @Override
    protected void initEvent() {
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(3000);
        scaleAnimation.setFillAfter(true);
        splashIv.startAnimation(scaleAnimation);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                goToMainOrLongin(true);
            }
        }, 3000);

    }

    @Override
    protected String setTitle() {
        return null;
    }

    @Override
    protected void showBack(TextView button_goback) {

    }

    @NonNull
    @Override
    public LoadingPresenter createPresenter() {
        return new LoadingPresenter();
    }
    private void goToMainOrLongin(boolean isTomain) {
        if ( SPUtil.getBoolean("isLog",false)||isTomain) {
            startActivity(new Intent(LoadingActivity.this, MainActivity.class));
        } else {
            startActivity(new Intent(LoadingActivity.this, LoginActivity.class));
        }
        finish();
    }


}
